package cn.xutongxue.gtms.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.xutongxue.gtms.entity.dto.MenuListVo;
import cn.xutongxue.gtms.mapper.MenuMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.xutongxue.gtms.entity.Menu;
import cn.xutongxue.gtms.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author Administrator
* @description 针对表【menu(菜单)】的数据库操作Service实现
* @createDate 2023-10-08 14:33:36
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu>
    implements MenuService{

    @Resource
    private MenuMapper menuMapper;
    @Override
    public List<MenuListVo> getMenuList(String role) {
        List<Menu> menuList = menuMapper.getMenuList(role);
        return generateMenuListVo(menuList);
    }

    private List<MenuListVo> generateMenuListVo(List<Menu> menuList) {
        List<MenuListVo> menuListVos = new ArrayList<>();
        for (Menu m : menuList) {
            MenuListVo menuListVo = new MenuListVo();
            if (m.getPId() == 0) {
                BeanUtil.copyProperties(m, menuListVo);
                menuListVos.add(menuListVo);
            }
        }
        return menuListVos;
    }
}




